//
//  SHWelcomeViewController.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/22.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit

class SHWelcomeViewController: UIViewController {

    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootViewControllerNoti, object: "welcome")
                })
        }
    }
    
    private func setupUI(){
        
        view.addSubview(headImageView)
        
        view.addSubview(messageLabel)
        
        
        
        headImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            
            make.size.equalTo(CGSizeMake(90, 90))
            
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
    }
    
    
    private lazy var bgImageView: UIImageView = UIImageView(imgName: "ad_background")
    
    private lazy var headImageView: UIImageView = {
        let image = UIImageView(imgName: "avatar_default_big")
        image.sh_setImage(SHUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        image.layer.borderColor = ThemeColor.CGColor
        
        image.layer.borderWidth = 2
        
        image.layer.cornerRadius = 45
        
        image.layer.masksToBounds = true

        return image
        
    }()
    
    private lazy var messageLabel: UILabel = {
        let lab = UILabel(textColor: UIColor.darkGrayColor(), textFont: 18)
        
        lab.text = "欢迎回来"
        
        lab.textAlignment = .Center
        
        lab.alpha = 0
        
        return lab
    }()
}
